import argparse
import requests
import re
import json
parser = argparse.ArgumentParser()

parser.add_argument('--name', '-n', type=str, default='')

args = parser.parse_args()

keyword = args.name
header = {
        'Cookie': 'OCSSID=4df0bjva6j7ejussu8al3eqo03',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',

    }
url = 'https://image.baidu.com/search/acjson?'
param = {
        'tn': 'resultjson_com',
        'logid': '10118629074475114798',
        'ipn': 'rj',
        'ct': '201326592',
        'is': '',
        'fp': 'result',
        'queryWord': keyword,
        'cl': '2',
        'lm': '-1',
        'ie': 'utf-8',
        'oe': 'utf-8',
        'adpicid': '',
        'st': '-1',
        'z': '',
        'ic': '',
        'hd': '',
        'latest': '',
        'copyright': '',
        'word': keyword,
        's': '',
        'se': '',
        'tab': '',
        'width': '',
        'height': '',
        'face': '0',
        'istype': '2',
        'qc': '',
        'nc': '1',
        'fr': '',
        'expermode': '',
        'force': '',
        'pn': '0',
        'rn': '30',
        'gsm': 'b',
        '1616222616569': ''
    }
page_text = requests.get(url=url, headers=header, params=param)
page_text.encoding = 'utf-8'
page_text1 = page_text.text

html = re.findall('"thumbURL":"(.*?)"', page_text1)
if len(html):
    info_list = html


    img_path_list = []
    x = 1
    for i in info_list:
        if x < 5:
            img_path_list.append(i)
        x = x + 1
    if len(img_path_list):
        print(json.dumps(img_path_list))
